<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>日期</title>
    <script>
        //静态方法
        {   //1.now方法返回自 1970 年 1 月 1 日 00:00:00 (UTC) 到当前时间的毫秒数
            let time = Date.now();
            console.log(time);
            //2.parse计算给出时间点到1970 年 1 月 1 日 00:00:00 (UTC)的毫秒数
            let time2 = Date.parse('01 Jan 1970 00:00:00 GMT');
            let time3 = Date.parse('04 Dec 1995 00:12:00 GMT');
            console.log(time2, time3);
            //3.Date.UTC(年, 月, 日,时, 分, 秒)月份需要减一写，年份若为四位数需加一
            let utcDate1 = new Date(Date.UTC(96, 1, 2, 3, 4, 5));
            let utcDate2 = new Date(Date.UTC(0, 0, 0, 0, 0, 0));
            let utcDate3 = new Date(Date.UTC(2007, 0, 0, 0, 0, 0));
            console.log(utcDate3)
            console.log(utcDate1, utcDate2)
            console.log(utcDate1.toUTCString());
            console.log(utcDate2.toUTCString());
        }
        //实例方法
        {
            //getDate输出日期对象的日期
            let birthday = new Date('April 29, 2000 23:15:30');
            let date1 = birthday.getDate();
            console.log(date1);
            //getDay输出日期对象是周几
            let date2 = birthday.getDay();
            console.log(date2);
            //getFullYear输出日期对象的年份
            console.log(birthday.getFullYear());
            //getMonth输出日期对象的月份,月份需手动加一
            console.log(birthday.getMonth() + 1);
            //getHours输出日期对象的时
            console.log(birthday.getHours());
            //getMinutes输出日期对象的分
            console.log(birthday.getMinutes());
            //getSeconds输出日期对象的秒
            console.log(birthday.getSeconds());
            //setMilliseconds给日期对象设置毫秒，getMilliseconds获取日期对象毫秒
            birthday.setMilliseconds(233);
            console.log(birthday.getMilliseconds());
        }
        {
            //getTime返回对象到1970 年 1 月 1 日 00:00:00 (UTC)的毫秒数
            let day = new Date('May 01, 2012 23:15:30');
            console.log(day.getTime());
        }
        {
            //getTimezoneOffset方法返回协调世界时（UTC）相对于当前时区的时间差值，单位为分钟。
            let date1 = new Date('August 19, 1975 23:15:30 GMT+07:00');
            let date2 = new Date('August 19, 1975 15:15:30 GMT-02:00');
            console.log(date2.getTimezoneOffset());
            console.log(date1.getTimezoneOffset() === date2.getTimezoneOffset());
            let x = new Date();
            let currentTimeZoneOffsetInHours = x.getTimezoneOffset() / 60;
            console.log(currentTimeZoneOffsetInHours)
        }
        {
            //getUTCDate 以世界时为标准，返回一个指定的日期对象为一个月中的第几天
            let today = new Date();
            let day = today.getUTCDate();
            console.log(day)
            //getUTCDay 以世界时为标准，返回一个指定的日期对象为一星期中的第几天，其中 0 代表星期天
            console.log(today.getUTCDay())
            //类似的getUTC Date/day/FullYear/Month/Hours/Minutes/Seconds/Milliseconds
            //都存在类似效果
        }
        {
            //类似的set Date/day/FullYear/Month/Hours/Minutes/Seconds/Milliseconds
            //根据本地时间为一个日期对象设置日期对应参数
            let date = new Date();
            date.setDate(12);
            date.setFullYear(1999);
            date.setHours(21);
            date.setMonth(3);
            date.setMinutes(12);
            console.log(date);
            //类似setUTC Date/day/FullYear/Month/Hours/Minutes/Seconds/Milliseconds
            //根据全球时间设置特定 date 对象的日期对应参数
        }
        {
            //setTime方法以一个表示从 1970-1-1 00:00:00 UTC 计时的毫秒数为来为 Date 对象设置时间
            let launchDate = new Date('August 1, 1999, 12:00:00');
            let futureDate = new Date();
            futureDate.setTime(launchDate.getTime());
            console.log(futureDate);
            let fiveMinutesInMillis = 5 * 60 * 1000;
            futureDate.setTime(futureDate.getTime() + fiveMinutesInMillis);
            console.log(futureDate);
        }
        {
            //toDateString方法以美式英语和人类易读的形式返回一个日期对象日期部分的字符串
            let event = new Date(1993, 6, 28, 14, 39, 7);
            console.log(event.toString());
            console.log(event.toDateString());
            //toISOString方法返回一个 ISO（ISO 8601 Extended Format）格式的字符串：
            // YYYY-MM-DDTHH:mm:ss.sssZ
            console.log(event.toISOString());
            let jsString = event.toJSON();
            console.log(new Date(jsString).toUTCString());
            console.log(jsString);

            // console.log(event)
            // console.log(event)
        }
        {
            const event = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
            const options = {
                weekday: 'long',
                year: 'numeric',
                month: 'long',
                day: 'numeric',
            };
            console.log(event.toLocaleDateString('de-DE', options));
            console.log(event.toLocaleDateString('ar-EG', options));
            console.log(event.toLocaleDateString('ch', options));
        }
        {
            const event = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
            console.log(event.toLocaleString('en-GB', { timeZone: 'UTC' }));
            console.log(event.toLocaleString('ko-KR', { timeZone: 'UTC' }));
            console.log(event.toLocaleString('ch', { timeZone: 'UTC' }));
            console.log(event.toLocaleTimeString('en-US'));
        }
        {
            const event = new Date('August 19, 1975 23:15:30');
            console.log(event.toString());
            console.log(event.toTimeString());
            console.log(event.toUTCString());
        }

    </script>
</head>

<body>

</body>

</html>